<template>
	<view class="actions-modal" v-if="visible" @tap="close">
		<view class="actions-content" @tap.stop>
			<view class="actions-header">
				<text class="header-title">消息操作</text>
				<view class="close-btn" @tap="close">
					<text class="close-text">✕</text>
				</view>
			</view>
			
			<view class="actions-list">
				<view class="action-item" @tap="markAsRead" v-if="!message.read">
					<image src="/static/svg/bookmark.svg" class="action-icon" />
					<text class="action-text">标记为已读</text>
				</view>
				
				<view class="action-item" @tap="markAsUnread" v-if="message.read">
					<image src="/static/svg/bookmark.svg" class="action-icon" />
					<text class="action-text">标记为未读</text>
				</view>
				
				<view class="action-item" @tap="deleteMessage">
					<image src="/static/svg/minus.svg" class="action-icon" />
					<text class="action-text delete">删除消息</text>
				</view>
				
				<view class="action-item" @tap="reportMessage" v-if="message.type !== 'system'">
					<image src="/static/svg/more.svg" class="action-icon" />
					<text class="action-text">举报</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
import { defineProps, defineEmits } from 'vue'

const props = defineProps({
	visible: {
		type: Boolean,
		default: false
	},
	message: {
		type: Object,
		default: () => ({})
	}
})

const emits = defineEmits(['close', 'markAsRead', 'markAsUnread', 'delete', 'report'])

const close = () => {
	emits('close')
}

const markAsRead = () => {
	emits('markAsRead', props.message)
	close()
}

const markAsUnread = () => {
	emits('markAsUnread', props.message)
	close()
}

const deleteMessage = () => {
	uni.showModal({
		title: '确认删除',
		content: '确定要删除这条消息吗？',
		success: (res) => {
			if (res.confirm) {
				emits('delete', props.message)
				close()
			}
		}
	})
}

const reportMessage = () => {
	uni.showToast({
		title: '举报成功',
		icon: 'success'
	})
	emits('report', props.message)
	close()
}
</script>

<style scoped>
.actions-modal {
	position: fixed;
	top: 0;
	left: 0;
	right: 0;
	bottom: 0;
	background: rgba(0, 0, 0, 0.5);
	display: flex;
	align-items: flex-end;
	z-index: 1000;
}

.actions-content {
	width: 100%;
	background: white;
	border-radius: 20px 20px 0 0;
	padding: 20px;
	animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
	from {
		transform: translateY(100%);
	}
	to {
		transform: translateY(0);
	}
}

.actions-header {
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin-bottom: 20px;
	padding-bottom: 15px;
	border-bottom: 1px solid #eee;
}

.header-title {
	font-size: 18px;
	font-weight: 600;
	color: #333;
}

.close-btn {
	width: 30px;
	height: 30px;
	display: flex;
	align-items: center;
	justify-content: center;
	border-radius: 50%;
	background: #f5f5f5;
}

.close-text {
	font-size: 16px;
	color: #666;
}

.actions-list {
	display: flex;
	flex-direction: column;
}

.action-item {
	display: flex;
	align-items: center;
	padding: 15px 0;
	border-bottom: 1px solid #f0f0f0;
	gap: 15px;
}

.action-item:last-child {
	border-bottom: none;
}

.action-item:active {
	background: #f8f9fa;
}

.action-icon {
	width: 20px;
	height: 20px;
	opacity: 0.7;
}

.action-text {
	font-size: 16px;
	color: #333;
}

.action-text.delete {
	color: #ff4757;
}
</style>